package com.smartleanx.module.hrm.controller.admin.employee;

import com.smartleanx.module.hrm.controller.admin.employee.edu.EmployeeEducationExperienceRespVO;
import com.smartleanx.module.hrm.controller.admin.employee.edu.EmployeeEducationExperienceSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;


import com.smartleanx.module.hrm.dal.dataobject.employee.EmployeeEducationExperienceDO;
import com.smartleanx.module.hrm.service.employee.EmployeeEducationExperienceService;

@Tag(name = "管理后台 - 员工教育经历")
@RestController
@RequestMapping("/hrm/employee-education-experience")
@Validated
public class EmployeeEducationExperienceController {

    @Resource
    private EmployeeEducationExperienceService employeeEducationExperienceService;

    @PostMapping("/create")
    @Operation(summary = "创建员工教育经历")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-education-experience:create','hrm:employee:update')")
    public CommonResult<Long> createEmployeeEducationExperience(@Valid @RequestBody EmployeeEducationExperienceSaveReqVO createReqVO) {
        return success(employeeEducationExperienceService.createEmployeeEducationExperience(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新员工教育经历")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-education-experience:update','hrm:employee:update')")
    public CommonResult<Boolean> updateEmployeeEducationExperience(@Valid @RequestBody EmployeeEducationExperienceSaveReqVO updateReqVO) {
        employeeEducationExperienceService.updateEmployeeEducationExperience(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工教育经历")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-education-experience:delete','hrm:employee:update')")
    public CommonResult<Boolean> deleteEmployeeEducationExperience(@RequestParam("id") Long id) {
        employeeEducationExperienceService.deleteEmployeeEducationExperience(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工教育经历详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-education-experience:query','hrm:employee:query')")
    public CommonResult<EmployeeEducationExperienceRespVO> getEmployeeEducationExperience(@RequestParam("id") Long id) {
        EmployeeEducationExperienceDO employeeEducationExperience = employeeEducationExperienceService.getEmployeeEducationExperience(id);
        return success(BeanUtils.toBean(employeeEducationExperience, EmployeeEducationExperienceRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "根据员工id获得教育经历列表")
    @Parameter(name = "employeeId", description = "员工编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-education-experience:query','hrm:employee:query')")
    public CommonResult<List<EmployeeEducationExperienceRespVO>> getEmployeeEducationExperienceList(@RequestParam("employeeId") Long employeeId) {
        List<EmployeeEducationExperienceDO> educationExperienceList = employeeEducationExperienceService.getEmployeeEducationExperienceList(employeeId);
        return success(BeanUtils.toBean(educationExperienceList, EmployeeEducationExperienceRespVO.class));
    }

}